﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.Admin.ServiceReference1;

namespace CMP.ERP.Admin.Controllers
{
    public class Express_mateController : Controller
    {
        //
        // GET: /Express_mate/
        ServiceReference1.Service1Client client = new Service1Client();
        public ActionResult Exress_mate_Show()
        {
            
            //List<ServiceReference1.FORMDHLUPSInfo> list = new List<FORMDHLUPSInfo>();
            
            return View();
        }
        public ActionResult Exress_mate_Show1(int did)
        {
            List<FORMDHLUPSInfo> list = new List<FORMDHLUPSInfo>();
            list = client.FORMDHLUPSInfoShow(did).ToList();
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public ActionResult Exress_mate_Delete(int id)
        {
            if (client.FORMDHLUPSInfodDelete(id) > 0)
            {
                return Content("<script>alert('删除成功');location.href='/Express_mate/Exress_mate_Show'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/Express_mate/Exress_mate_Show'</script>");
            }
        }
        /// <summary>
        /// 获取快递名称
        /// </summary>
        /// <returns></returns>
        public ActionResult kuaidiname()
        {
            List<ServiceReference1.DHLUPSFEDEXEMSInfo> list = new List<DHLUPSFEDEXEMSInfo>();
            list = client.kuaidiname().ToList();
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 根据id获取城市
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public ActionResult GetidCity(int pid)
        {
            List<CityInfo> list = new List<CityInfo>();
            list = client.GetidCity(pid).ToList();
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 根据快递编号获取城市编号
        /// </summary>
        /// <param name="rid"></param>
        /// <returns></returns>
        public ActionResult FORMDHLUPSInfoGetid(int pid)
        {
            List<FORMDHLUPSInfo> list = new List<FORMDHLUPSInfo>();
            list = client.FORMDHLUPSInfoGetid(pid).ToList();
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public int Exress_mate_Update(int pid, string str)
        {
            string[] Oid = str.Split(',');
            if (client.FORMDHLUPSInfoGetid(pid).Count() == 0)
            {
                for (int i = 0; i < Oid.Length; i++)
                {
                    client.FORMDHLUPSInfoAdd(pid, Oid[i]);
                }
                return 1;
            }
            if (client.FORMDHLUPSInfoGetid(pid).Count() > 0)
            {
                client.kuaidisahnchu(pid);
                if (Oid.Length == 1)
                {
                    return 1;
                }
                else
                {
                    for (int i = 0; i < Oid.Length; i++)
                    {
                        client.FORMDHLUPSInfoAdd(pid, Oid[i]);
                    }
                    return 1;
                }   
            }
            else
            {
                return 0;
            }
        }
    }
}
